import { ListRawState } from "../../types"

const initState = {
  // 数据
  list: [] as ListRawState[],
  // 分页参数
  pageSize: 10,
  pageCode: 1,
  // 表示数据是否加载完毕
  finished: false
}

const listReducer = (state = initState, action: any) => {
  switch(action.type) {
    case 'setList': {
      return {
        ...state,
        list: state.list.concat(action.payload)
      }
    }
    case "addPageCode": {
      return {
        ...state,
        pageCode: state.pageCode + 1
      }
    }
    case 'setFinish': {
      return {
        ...state,
        finished: action.payload as boolean
      }
    }
    default: return state;
  }
}

export default listReducer